<template>
	<view>
		<!-- 普通弹窗 -->
		<uni-popup ref="popup" @change="change" >
			
			<view class="popup-content" style="padding-bottom: 40rpx;">
				<uni-title type="h3" title="登陆拜访记录" align="center"></uni-title>
				<view class="vdivider"></view>
				
				<view style="margin-top: 30rpx;">
					<uni-forms :modelValue="formData" >
						<uni-forms-item label="拜访时间" required label-width=80>
							<uni-datetime-picker type="date" v-model="formData.datetimesingle"/>
						</uni-forms-item>
						<uni-forms-item label="拜访店名" required label-width=80>
							<uni-easyinput type="text" v-model="formData.store_name" placeholder="请输入姓名" />
						</uni-forms-item>
						<uni-forms-item label="拜访性质" required label-width=80>
							<uni-data-select
							        v-model="formData.type"
							        :localdata="selectRange"
							        @change="selectChange"
							      ></uni-data-select>
						</uni-forms-item>
						<uni-forms-item label="拜访商户" required label-width=80>
							<uni-data-select
							        v-model="formData.mer_id"
							        :localdata="merRange"
							        @change="merChange"
							      ></uni-data-select>
						</uni-forms-item>
						<uni-forms-item label="随行商务" label-width=80>
							<zxz-uni-data-select v-model="formData.partner" :filterable="true" :localdata="teamlist" :multiple="true"></zxz-uni-data-select>
							<!-- <uni-easyinput type="text" v-model="formData.partner" placeholder="请输入随行商务姓名" /> -->
						</uni-forms-item>
						<uni-forms-item label="拜访结果"  label-width=80>
							<uni-easyinput type="textarea" v-model="formData.content" placeholder="请输入拜访结果" />
						</uni-forms-item>
						<uni-forms-item label="是否成交"  label-width=80>
							<uni-data-checkbox v-model="formData.is_deal" :localdata="isdeals" />
						</uni-forms-item>
						<uni-forms-item label="建议支持"  label-width=80>
							<uni-easyinput type="textarea" v-model="formData.remark" placeholder="请输入建议或支持" />
						</uni-forms-item>
					</uni-forms>
					<button @click="submitForm" size="default" type="default"
						style="color:#ffffff;background-color:#3ACD90;font-weight: bold;"
						hover-class="is-hover">提交</button>
		
				</view>
				
			</view>
		</uni-popup>
			
	</view>
</template>

<script>
import form from "../uni_modules/uview-ui/libs/config/props/form";
import {
	visitLogAdd,
	myBusinessList,
	myTeamList
} from "@/common/apis/other.js"
export default{
	data(){
		return{
			teamlist: [],
			selectRange: [
			  { value: 0, text: "首次" },
			  { value: 1, text: "跟进" },
			  { value: 2, text: "服务商家" },
			],
			formData:{
				store_name:"",
				datetimesingle:"",
				type:0,
				partner:"",
				content:"",
				remark:"",
				is_deal:0	
			},
			// 单选数据源
			isdeals: [{
				text: '未成交',
				value: 0
			}, {
				text: '已成交',
				value: 1
			}],
			merRange:[],
		}
	},
	created() {
		myBusinessList().then(res=>{
			console.log('res',res)
			if(res.status == 200){
				const transformedData = res.data.list.map(item => ({
				  value: item.mer_id.toString(),
				  text: item.mer_name
				}));
				this.merRange = transformedData
			}
		})
		myTeamList().then(res=>{
			console.log('res',res)
			if(res.status == 200){
				const transformedData = res.data.list.map(item => ({
				  value: item.business_id.toString(),
				  text: item.real_name
				}));
				this.teamlist = transformedData
			}
		})
	},
	methods:{
		change(e) {
			console.log('当前模式：' + e.type + ',状态：' + e.show);
		},
		selectChange(){
			console.log('selectChange')
		},
		merChange(){
			console.log('merChange')
		},
		
		toggle() {
			this.$refs.popup.open('center')
		},
		submitForm(){
			
			
			this.formData.partner = this.formData.partner.join(',')
			console.log("submitForm",this.formData)
			visitLogAdd(this.formData).then( res => {
				console.log("res",res)
				if(res.status == 200){
					uni.showToast({
						title: '提交成功',
						duration: 2000
					});
					this.$refs.popup.close()
				}else{
					uni.showToast({
						title: '提交失败',
						duration: 2000
					});
				}
			})
		}
	}
}
</script>

<style scoped>
	.popup-content {
		background-color: #fff;
		width: 660rpx;
		border-radius: 20rpx;
		padding: 0 20rpx;
		
	}
</style>